<template>
  <v-form v-model="valid" ref="categoryForm">
    <v-text-field
      label="分类名称"

      v-model="category.name"

      :rules="[v => !!v || '分类名称不能为空']"
      :counter="10"
      required
    />

    <v-layout class="my-4">
      <v-btn @click="submit" color="primary">提交</v-btn>
      <v-btn @click="clear" color="warning">重置</v-btn>
    </v-layout>
  </v-form>
</template>


<script>
  import config from '@/config';

  export default {
    name: "categoryForm",
    data(){
      return{
        valid:false,
        category: {
          name: "",
          parentId:0,
          isParent:0,
          sort:0,
      },
      }
    },
    methods: {
      submit() {
        // 表单校验
        if (this.$refs.categoryForm.validate()) {
          this.$http({
            method: this.isEdit ? 'put' : 'post',
            url: '/item/category',
            data: this.$qs.stringify(this.category)
          }).then(() => {
            // 关闭窗口
            this.$message.success("保存成功！");
            this.closeWindow();
          }).catch(() => {
            this.$message.error("保存失败！");
          });
        }
      },
      clear() {
        // 重置表单
        this.$refs.brandForm.reset();
        this.categories = [];
      },
      closeWindow() {
        this.$emit("close");
      }
    }
  }

</script>

<style scoped>

</style>
